package CMD;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;

import gameElements.role.Lead;
import kitBox.SaveFile;
import reader.IniReader;
import reader.SaveFileReader;
 
public class SaveCMD {
	private static SaveCMD sc = new SaveCMD();
	public static SaveCMD getSaveCMD()
	{
		return sc;
	}
	
	public void saveGame()
	{
		SaveFile sf = SaveFileReader.getSaveFileReader().getNowSaveFile();
		sf.setLead((Lead)RoleCMD.getRoleCMD().getRole(0));
		sf.setSceneDir(MapCMD.getMapCMD().getNowSceneDir());
		sf.setMapName(MapCMD.getMapCMD().getNowMapName());
		sf.setLastLoadTime(System.currentTimeMillis());
		int index = SaveFileReader.getSaveFileReader().getSaveIndex();
		
		String savePath = IniReader.getIniReader().getValue("[DIR]", "SaveDir");
		savePath = savePath+index +".sav";
		
		try {
			ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(new File(savePath)));
			oos.writeObject(sf);
			oos.flush();
			oos.close();
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
